import { Style, Fill, Text, Icon } from 'ol/style';
import videoImg from '@/assets/map/video.png'
import sensorImg from '@/assets/map/sensor.png'
import deviceImg from '@/assets/map/device.png'
import { mapManager } from '../MapManager';

var DEVICE_Z = 1000;
/**
 * 设备样式的封装类
 */
class DeviceStyle {
    
    /**
     * 获取地块样式
     * @public
     * @param {import("../../../util/typedef").DeviceInfo} device   设备信息
     * @return {import('ol/style/Style').StyleFunction} 返回样式
     */
    static getStyle(device) {
        return function (feature) {
            var _typeId = null;
            if (device.deviceType != null) _typeId = device.deviceType.id;
            var src = "";
            if (_typeId == "1") { //摄像头
                src = videoImg;
            } else if (_typeId == "2") { //传感器
                src = sensorImg;
            } else if (_typeId == "3") { //其他
                src = deviceImg;
            } else {
                src = deviceImg;
            }
    

            var zoom = mapManager.getMap().getView().getZoom();
            var fontSize = 12;
            var scale = 1;
           

            if (zoom < 15.1) {
                fontSize = 0;
                scale = 0;
            }else{
                fontSize = 12;
                scale = 1;
            }

            var style = new Style({
                image: new Icon(({
                    anchor: [0.6, 0.5],
                    anchorXUnits: 'fraction',
                    anchorYUnits: 'fraction',
                    src: src,
                    scale:scale,
                    rotateWithView: true
                })),
                text: new Text({
                    font: fontSize+"px 宋体",
                    fill: new Fill({
                        color: "#fff"
                    }),
                    offsetY: 6,
                    textBaseline: "top",
                    text: device.name
                }),
                zIndex: DEVICE_Z
            }); 

            return style;
        }


    }

    
}


export default DeviceStyle;